/**
 * @class   wosh::network::WebDownloader
 * @brief   
 *
 ****************************************************************************
 * @version 0.8.462 $Id: WebDownloader.h 2891 2010-08-12 01:58:59Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Network_WebDownloader_H__
 #define __WOSH_Network_WebDownloader_H__

 #include <core/Object.h>
 #include <core/LogContext.h>
 #include <core/Reflection.h>
 #include <core/Variant.h>


namespace wosh {
 namespace network {

#define _WebDownloader_DEBUG_ENABLED

class WebDownloader;

class IWebDownloaderListener
 {
	public:
//		virtual void udpIncomingDatagram( wosh::network::WebDownloader* downloader ) = 0;

	public:
		virtual ~IWebDownloaderListener() { }

}; // class def


class WebDownloader : public IReflection
 {
	WOSH_CLASSNAME(wosh::network::WebDownloader)
	WOSH_CLASS_ABSTRACT(true)

	public:
		/// request options
		enum OPTION {
			OPTION_NONE				= 0x00,	///< no param
			OPTION_URL				= 0x01,	///< string param (i.e. "http://www.mydomain.com/mypage.html")
			OPTION_USERPWD			= 0x02,	///< string param (i.e. "myname:thesecret")
			OPTION_PROXYUSERPWD		= 0x04,	///< string param (i.e. "myname:thesecret")
			OPTION_POST				= 0x08,	///< bool param (do a HTTP-POST request)
			OPTION_POSTFIELDS		= 0x10,	///< string param (i.e. "field1=value1&field2=value2")

			OPTION_FOLLOWLOCATION	= 0x20	///< bool param (follow redirect)
		 };


	public:
		/**
		 * @brief   Empty constructor, init vars.
		 */
		WebDownloader();
		/**
		 * @brief   Empty destructor
		 */
		virtual ~WebDownloader() { }

	public:

		virtual WRESULT execute() = 0;

		virtual WRESULT download( const std::string& base_url, const std::string& local_filename ) = 0;


/** @name Getters
 * @{
 ******************************************************************************/
	public:
		virtual bool isInitialized() const = 0;

		inline wosh::network::IWebDownloaderListener* getListener()		{ return this->listener; }

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		virtual WRESULT setUrl( const std::string& base_url ) = 0;
		virtual WRESULT setTargetFile( const std::string& local_filename ) = 0;

		virtual WRESULT setOption( OPTION option, const Variant& value ) = 0;
		virtual WRESULT clearOptions() = 0;

		virtual inline void setListener( wosh::network::IWebDownloaderListener* web_listener )	{ this->listener = web_listener; }

//@}
/** @name Internal vars
 * @{
 ******************************************************************************/
	protected:

		wosh::network::IWebDownloaderListener* listener;

#ifdef _WebDownloader_DEBUG_ENABLED
		mutable wosh::LogContext Log;
#endif

//@}

}; // class def

 }; // namespace network
}; // namespace wosh

#endif //__WOSH_Network_WebDownloader_H__
